********************************************************************************
********************************************************************************
* This do file replicates all main figures of the employer 
* surveys: Figure 2, 3, 5, and 6
********************************************************************************
********************************************************************************

*******************************************************************************
* Figure 2. Importance of language skills in Swedish.
********************************************************************************
use "Data/data_lilla_sprakenkat_occ_level", clear

replace  occ = "Preschool teachers" if occ == "barnskötare"
replace  occ = "Shop sales assistants" if occ == "butikssäljare"
replace  occ = "Computer prof." if occ == "dataspecialist"
replace  occ = "Accounting clerks" if occ == "ekonomiassistent"
replace  occ = "Drivers" if occ == "fordonsförare"
replace  occ = "Business sales persons" if occ == "företagssäljare"
replace  occ = "Chefs" if occ == "kock"
replace  occ = "Office assistants" if occ == "kontorsassistent"
replace  occ = "Customer service workers" if occ == "kundtjänstpersonal"
replace  occ = "Warehouse staff workers" if occ == "lagerpersonal"
replace  occ = "Cleaners" if occ == "lokalvårdare"
replace  occ = "Mechanics" if occ == "mekaniker"
replace  occ = "HR assistants" if occ == "personaladministratör"
replace  occ = "Personal assistants" if occ == "personligassistent"
replace  occ = "Accountants" if occ == "redovisningsekonom"
replace  occ = "Waiters/waitresses" if occ == "restaurangbiträde"
replace  occ = "IT support technicians" if occ == "supporttekniker"

graph bar Lang_important_gr4,  over(occ, sort(Lang_important_gr4)   label(angle(45))) ///
ytitle("Fraction") ylab(0(0.2)1, nogrid) bar(1, fcolor(gs3) lcolor(black)) graphregion(color(gs16)) 

*******************************************************************************
* Figure 3. Language proficiency ratings of cover letters.
*******************************************************************************

use "Data/data_stora_sprakenkaten_JHR", clear
foreach var of varlist * {
 local contains_X3 = strpos("`var'", "03") | strpos("`var'", "13") | strpos("`var'", "23") | strpos("`var'", "33")
 if `contains_X3' > 0 {
  drop `var'
 }
}

foreach var of varlist * {
 preserve
  keep `var'
  gen language_level = substr("`var'", 4, 1) 
  destring language_level, replace
  gen rating_swedish = `var' if substr("`var'", 5, 1) == "1" 
  drop `var'
  gen recr_id = _n
  compress
  save Data/tmp_rating_swedish_`var', replace
 restore
}

foreach var of varlist * {
 preserve
  keep `var'
  gen language_level = substr("`var'", 4, 1) 
  destring language_level, replace
  gen probability_callback = `var' if substr("`var'", 5, 1) == "2" 
  drop `var'
  gen recr_id = _n
  compress
  save Data/tmp_probability_callback_`var', replace
 restore
}

local first_time = 1 
foreach var of varlist * {
 if `first_time' == 1 {
  clear
  local first_time = 0
 }
 append using Data/tmp_rating_swedish_`var', force
 erase Data/tmp_rating_swedish_`var'.dta
}

drop if rating_swedish == .
sort recr_id language_level
replace language_level = (-1) * language_level + 4
compress
save Data/tmp_rating_swedish, replace

* Survey B 
use "Data/data_lilla_sprakenkat_employer_level_JHR", clear
keep rating_good_CV  occ
rename rating_good_CV rating_swedish_Survey_B
gen language_level = 3
compress
save Data/tmp_rating_good_CV, replace
use "Data/data_lilla_sprakenkat_employer_level_JHR", clear
keep rating_bad_CV  occ
rename rating_bad_CV rating_swedish_Survey_B
gen language_level = 1
append using Data/tmp_rating_good_CV, force
erase Data/tmp_rating_good_CV.dta

* Add Survey A (just to be able to plot in the same graph)
append using Data/tmp_rating_swedish, force
erase Data/tmp_rating_swedish.dta
collapse rating_swedish rating_swedish_Survey_B, by(language_level)

twoway (scatter rating_swedish_Survey_B language_level, ///
mfcolor(white) mlcolor(black) msymbol(triangle) ///
legend(symxsize(10) cols(1) label(1 "Survey 1") label(2 "Survey 2"))) ///
(connected rating_swedish language_level, ///
ytitle("Rating") ///
xtitle("Language level") ///
ylabel(,nogrid) graphregion(color(gs16)) ///
xlabel(,nogrid) ///
mcolor(black) lcolor(black) ylabel(0(1)7) yscale(range(0(1)7))) 

*******************************************************************************
* Figure 5. The recruiters’ motivation of their rating of the job applicants’ employability.
* See Appendix Section E.3 for the details of our classification of 
* the recruiters’ motivations.
*******************************************************************************

clear
set obs 4
gen FractionLangLevel1 = .
gen FractionLangLevel2 = .
gen TypeOfComment = .
replace TypeOfComment = _n

label define lbl_TypeOfComment 1 "Language" 2 "Obs. characteristics" 3 "Unobs. characteristics" 4 "Unclear"
label values TypeOfComment lbl_TypeOfComment

replace FractionLangLevel1 = .80 if TypeOfComment == 1
replace FractionLangLevel2 = .75 if TypeOfComment == 1
replace FractionLangLevel1 = .12 if TypeOfComment == 2
replace FractionLangLevel2 = .12 if TypeOfComment == 2
replace FractionLangLevel1 = .05 if TypeOfComment == 3
replace FractionLangLevel2 = .06 if TypeOfComment == 3
replace FractionLangLevel1 = .03 if TypeOfComment == 4
replace FractionLangLevel2 = .07 if TypeOfComment == 4

graph bar FractionLangLevel1 FractionLangLevel2 , over(TypeOfComment,  label(angle(45))) ///
ytitle("Fraction") bargap(10) ///
ylabel(,nogrid) graphregion(color(gs16)) ///
legend(symxsize(10) cols(1) label(1 "Language level 1") label(2 "Language level 3")) ///
bar(1, fcolor(gs10) lcolor(black)) bar(2, fcolor(black) lcolor(black))

*******************************************************************************
* Figure 6. Factors seen as a challenge when hiring people born outside the Nordic countries.
*******************************************************************************

use "Data/data_stora_sprakenkaten_JHR", clear
gen responded = 0
replace responded = 1 if B3_0 != . | B3_1 != . | B3_2 != . | B3_3 != . | B3_4 != . | B3_5 != . | BOther != ""
collapse (sum)B3_0 (sum)B3_1 (sum)B3_2 (sum)B3_3 (sum)B3_4 (sum)B3_5 (sum)responded
replace B3_0 = 100 * B3_0/responded
replace B3_1 = 100 * B3_1/responded
replace B3_2 = 100 * B3_2/responded
replace B3_3 = 100 * B3_3/responded
replace B3_4 = 100 * B3_4/responded
replace B3_5 = 100 * B3_5/responded

graph bar B3_0 B3_1 B3_2 B3_3 B3_4 B3_5 ,  ///
ylabel(,nogrid) bargap(100) ///
bar(6, color(white) lcolor(black)) bar(5, color(gs13) lcolor(black)) ///
bar(4, color(gs10) lcolor(black)) bar(3, color(gs7) lcolor(black)) ///
bar(2, color(gs4) lcolor(black)) bar(1, color(black) lcolor(black)) ///
legend(symxsize(10) cols(1) label(1 "Lack of knowledge of the Swedish language") ///
label(2 "Lack of knowledge of the Swedish society") ///
label(3 "Complicated government regulations") ///
label(4 "Difficult in assesing foreign competence") ///
label(5 "Risk of culture clashes in the workplace") ///
label(6 "Other") ///
region(lcolor(white))) graphregion(color(white)) legend(size(small)) 

